package com.sc.ktapplication.module.fragment

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog
import com.sc.ktapplication.R
import com.sc.ktapplication.common.base.BaseFragment
import com.sc.ktapplication.common.util.MMKVUtil
import com.sc.ktapplication.module.activity.*
import kotlinx.android.synthetic.main.fragment_mine.*

class MineFragment : BaseFragment() {

    override fun getLayoutId(): Int {
        return R.layout.fragment_mine
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
       // txtUserName.setText(mUser.getUserName())

        txtResetPwd.setOnClickListener { view1 -> startActivity(Intent(activity, UpdatePwdActivity::class.java))}
        txtMsg.setOnClickListener { v -> startActivity(Intent(activity, MsgActivity::class.java))}
        txtAboutUs.setOnClickListener { v -> startActivity(Intent(activity, AboutUsActivity::class.java))}
        txtUpdateApp.setOnClickListener { v -> startActivity(Intent(activity, AppUpdateActivity::class.java))}
        txtFeedback.setOnClickListener { v -> startActivity(Intent(activity, FeedbackActivity::class.java))}
        txtLogOut.setOnClickListener { v -> showLogoutDialog() }
    }


    private fun showLogoutDialog() {
        val dialog = MaterialDialog.Builder(context!!)
            .title("操作提示")
            .content("您确定要退出登录吗？")
            .negativeText("取消").negativeColor(resources.getColor(R.color.light_blue))
            .positiveText("确定").positiveColor(resources.getColor(R.color.light_blue))
            .onPositive { dialog1: MaterialDialog?, which: DialogAction? ->
                MMKVUtil.clearCache()
                startActivity(Intent(activity, LoginActivity::class.java))
                activity!!.finish()
            }
            .autoDismiss(true)
            .build()
        dialog.show()
    }
}
